import 'package:flutter/material.dart';
import 'package:common_utils/common_utils.dart';

///
/// 通用帮助类（日期、时间、屏幕等等）
///
class CommonUtils {
  static bool _initScreen = false;

  static String getCurrentDateTime() {
    return DateUtil.getDateStrByDateTime(DateTime.now());
  }

  static String getCurrentDateTimeZH() {
    return DateUtil.getDateStrByDateTime(DateTime.now(),
        format: DateFormat.ZH_NORMAL);
  }

  static void initScreen({BuildContext context}) {
    if (!_initScreen) {
      try {
        ScreenUtil.getInstance().init(context);
        _initScreen = true;
      } catch (e) {
        _initScreen = false;
      }
    }
  }

  static double getScreenWidth() {
    initScreen();

    return ScreenUtil.screenWidth;
  }

  static double getScreenHeight() {
    initScreen();

    return ScreenUtil.screenHeight;
  }

  static double getScreenDensity() {
    initScreen();

    return ScreenUtil.screenDensity;
  }

  static double getStatusBarHeight() {
    initScreen();

    return ScreenUtil.statusBarHeight;
  }

  static Widget createEmptyResult() {
    return _createCenterText("查询不到记录");
  }

  static Widget createErrorInfo() {
    return _createCenterText("正在加载，请稍候...");
  }

  static Widget _createCenterText(String text, {TextStyle style}) {
    return new Center(
      child: new Text(
        text,
        style: style,
      ),
    );
  }
}
